//
//  LJLClassificationPageTVC.m
//  聆听FM
//
//  Created by dllo on 16/6/6.
//  Copyright © 2016年 Dark. All rights reserved.
//

#import "LJLClassificationPageTVC.h"
#import "LJLClassificationPageCVC.h"
@implementation LJLClassificationPageTVC

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.minimumLineSpacing = 0;
        flowLayout.minimumInteritemSpacing = 0;
        flowLayout.itemSize = CGSizeMake((SCREENWIDTH) / 2.0, 40 * FITHEIGHT);
        flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        self.classificationPageCV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 120) collectionViewLayout:flowLayout];
        self.classificationPageCV.backgroundColor = [UIColor clearColor];
        self.classificationPageCV.delegate = self;
        self.classificationPageCV.dataSource = self;
        self.classificationPageCV.scrollEnabled = NO;
        [self.contentView addSubview:_classificationPageCV];
        
        [self.classificationPageCV registerClass:[LJLClassificationPageCVC class] forCellWithReuseIdentifier:@"LJLclassificationpageCVC"];
    }
    return self;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.dataSource.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    LJLClassificationPageCVC *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LJLclassificationpageCVC" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
    cell.layer.borderWidth = 1;
    cell.layer.borderColor = [UIColor whiteColor].CGColor;
    cell.model = [self.dataSource objectAtIndex:indexPath.row];
    return cell;
}
- (void)setDataSource:(NSMutableArray *)dataSource
{
    if (_dataSource != dataSource) {
        _dataSource = dataSource;
        
        [self.classificationPageCV reloadData];
    }
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    LJLClassificationPageModel *model = [self.dataSource objectAtIndex:indexPath.row];
    self.cBlock(model.id, model.title);
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
